Task

Use the image data/candy.jpg for this task!

Count the how many:

On the first figure above, there are some sprinkles in different colors. I can see sprinkles in 7 different colors, if I'm correct: yellow, green, blue, orange, white, red and pink. I'm going to use this intuition in next exercise to guess the number of colors on the picture.

Naturally, the color of the sprinkles are perceived to be the same, however, by taking a picture of them, the light reflected from them is not homogenious - as it can be seen on the second figure. So, solely looking at indivudal pixel values is not going to answer the question.

We need to group each pixel's color (by their RGB value), so that we can make some generalizations about the colors. One way to do is using the k-means algorithm.

Based on the figure above, we can say, that the k-means algorithm did a pretty good job by segmenting the picture by colors. Even though most of the colors seem to be accurate, there are two things going sideways. There's no brown candy in the image - so number 5 shouldn't be brown neither. Moreover, the first color seems to be the mixture of yellow and orange.

Fortunately, by increasing to $k=8$ now the algorithm detects the centroid of the yellow colored sprinkles.